//
//  LGAddReportHeaderView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/2.
//  新增报告--表头

#import "LGAddReportHeaderView.h"

#import "DatePickerTwoView.h"

@interface LGAddReportHeaderView()<DatePickerViewDelegate,LGPhotoPickerDelegate>
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *dateTitle;

/**   */
@property (nonatomic , strong)UIButton *programTitle;

/**   */
@property (nonatomic , strong)UIButton *photoTitle;


@end

@implementation LGAddReportHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)selectViewTouchAction:(UIButton *)sender{
    if(sender.superview == self.dateTF){
        //选择日期
        DatePickerTwoView *dateView = [[DatePickerTwoView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
        dateView.title = @"请选择日期";
        dateView.delegate = self;
        [[UIApplication sharedApplication].keyWindow addSubview:dateView];
        
    }else if (sender.superview == self.programTF){
        //选择检查项目
        if(self.delegate && [self.delegate respondsToSelector:@selector(selectInspectItemAction)]){
            [self.delegate selectInspectItemAction];
        }
    }
}


-(void)sendSelectDate:(NSString *)date index:(NSInteger)index{
    self.dateTF.text = date;
}

-(void)imagePickerHeightChanged:(CGFloat)height{
    self.photoView.frame = CGRectMake(viewPix(16), kMaxY(self.photoTitle.frame)+viewPix(8), Screen_W-viewPix(64), height);
    if(self.delegate && [self.delegate respondsToSelector:@selector(headViewHeightChanged:)]){
        CGFloat height = kMaxY(self.photoView.frame)+viewPix(40);
        [self.delegate headViewHeightChanged:height];
    }
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.dateTitle];
    [self.baseView addSubview:self.dateTF];
    [self.baseView addSubview:self.programTitle];
    [self.baseView addSubview:self.programTF];
    [self.baseView addSubview:self.photoTitle];
    [self.baseView addSubview:self.photoView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).offset(viewPix(16));
        make.right.equalTo(self).offset(-viewPix(16));
        make.bottom.equalTo(self).offset(-viewPix(8));
    }];
    
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIButton *)dateTitle{
    if(!_dateTitle){
        _dateTitle = [UIButton buttonWithTitle:@"日期" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#333333" imageName:@"必选项"];
        _dateTitle.frame = CGRectMake(viewPix(16), viewPix(14), viewPix(150), viewPix(21));
        _dateTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _dateTitle.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        _dateTitle.userInteractionEnabled = NO;
    }
    return _dateTitle;
}

-(UITextField *)dateTF{
    if(!_dateTF){
        _dateTF = [[UITextField alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.dateTitle.frame)+viewPix(8), Screen_W-viewPix(64), viewPix(40))];
        _dateTF.layer.borderColor = [UIColor colorWithString:@"#E0E0E0"].CGColor;
        _dateTF.layer.borderWidth = 1;
        _dateTF.layer.cornerRadius = 7;
        _dateTF.textColor = [UIColor colorWithString:@"#333333"];
        _dateTF.textAlignment = NSTextAlignmentLeft;
        _dateTF.placeholder = @"请选择日期";
        _dateTF.font = LGFont(14);
        _dateTF.leftViewMode = UITextFieldViewModeAlways;
        _dateTF.rightViewMode = UITextFieldViewModeAlways;
        _dateTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, viewPix(12), viewPix(40))];
        _dateTF.rightView = [self rightView];
        [_dateTF addSubview:[self actionButton]];
    }
    return _dateTF;
}

-(UIButton *)programTitle{
    if(!_programTitle){
        _programTitle = [UIButton buttonWithTitle:@"检查项目" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#333333" imageName:@"必选项"];
        _programTitle.frame = CGRectMake(viewPix(16), kMaxY(self.dateTF.frame)+viewPix(12), viewPix(150), viewPix(21));
        _programTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _programTitle.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        _programTitle.userInteractionEnabled = NO;
    }
    return _programTitle;
}


-(UITextField *)programTF{
    if(!_programTF){
        _programTF = [[UITextField alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.programTitle.frame)+viewPix(8), Screen_W-viewPix(64), viewPix(40))];
        _programTF.textColor = [UIColor colorWithString:@"#333333"];
        _programTF.layer.borderColor = [UIColor colorWithString:@"#E0E0E0"].CGColor;
        _programTF.layer.borderWidth = 1;
        _programTF.layer.cornerRadius = 7;
        _programTF.textAlignment = NSTextAlignmentLeft;
        _programTF.placeholder = @"请选择检查项目";
        _programTF.font = LGFont(14);
        _programTF.leftViewMode = UITextFieldViewModeAlways;
        _programTF.rightViewMode = UITextFieldViewModeAlways;
        _programTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, viewPix(12), viewPix(40))];
        _programTF.rightView = [self rightView];
        [_programTF addSubview:[self actionButton]];
    }
    return _programTF;
}

-(UIButton *)photoTitle{
    if(!_photoTitle){
        _photoTitle = [UIButton buttonWithTitle:@"上传图片" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#333333" imageName:@"必选项"];
        _photoTitle.frame = CGRectMake(viewPix(16), kMaxY(self.programTF.frame)+viewPix(12), viewPix(150), viewPix(21));
        _photoTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _photoTitle.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        _photoTitle.userInteractionEnabled = NO;
    }
    return _photoTitle;
}

-(LGPhotoPickerView *)photoView{
    if(!_photoView){
        _photoView = [[LGPhotoPickerView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.photoTitle.frame)+viewPix(8), Screen_W-viewPix(64), viewPix(72))];
        _photoView.delegate = self;
        _photoView.maxCount = 20;
    }
    return _photoView;
}

    
-(UIView *)rightView{
    UIView *baseView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, viewPix(30), viewPix(40))];
    UIImageView *tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    tipView.frame = CGRectMake(viewPix(6), viewPix(14), viewPix(12), viewPix(12));
    [baseView addSubview:tipView];
    return baseView;
}
    
-(UIButton *)actionButton{
    UIButton *actionBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    actionBtn.frame = CGRectMake(0, 0, Screen_W-viewPix(64), viewPix(40));
    [actionBtn addTarget:self action:@selector(selectViewTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    return actionBtn;
}
    
    
@end
